// -*- coding: utf-8 -*- 
/**
 * Project: AlgorithmsLearn
 *
 * @author: yanking
 * Create time: 2022-03-27 17:07
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.LeetCodeT.DateTrain;

import java.util.Arrays;

public class MissingRolls {
    /**
     * 缺失的数据
     */
    public int[] missingRolls(int[] rolls, int mean, int n) {
        int len = rolls.length, sum = mean * (len + n), mSum = Arrays.stream(rolls).sum(), nSum = sum - mSum;
        // 数值过小，不存在该情况
        if (nSum > (n * 6) || nSum < n) {
            return new int[]{};
        }
        int[] res = new int[n];
        if (nSum % n == 0) {
            // 可以平均分配
            for (int i = 0; i < n; i++) {
                res[i] = nSum / n;
            }
        } else {
            // 不可以平均分配
            int num = nSum / n, remain = nSum % n;
            for (int i = 0; i < n; i++) {
                if (remain > 0) {
                    res[i] = num + 1;
                    remain--;
                } else {
                    res[i] = num;
                }
            }
        }
        return res;
    }
}
